package com.fenghongzhang.day005;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


/**
 * A simple {@link Fragment} subclass.
 */
public class BlankFragment extends Fragment {
    private EditText input;
    private Button send;



    public BlankFragment() {
        // Required empty public constructor
    }

    //3,给声明的接口赋值
    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        myListener = (MyListener) getActivity();
    }
    //2,声明一个接口
    private MyListener myListener;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_blank, container, false);
        input = (EditText) inflate.findViewById(R.id.input);
        send = (Button) inflate.findViewById(R.id.send);
        send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //发送数据
                String s = input.getText().toString();
                //4, 调用
                myListener.send(s);
            }
        });
        return inflate;
    }
    //1,定义接口
    public interface MyListener{
        void send(String s);
    }
}
